import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-11-18
 * Time: 21:40
 */
public class test_3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int p = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            int num = 0;
            Arrays.sort(arr);

            int left = 0, right = 0, ret = 0;
            p *= 2;
            while(right < n)
            {
                while(arr[right] - arr[left] > p)
                {
                    left++;
                }
                ret = Math.max(ret, right - left + 1);
                right++;
            }
            System.out.println(ret);
        }
    }
}
